<template >
  <div>
    <div class="main">
      <div class="topBox">
        <div class="topBox-top">
          <div class="logo">
            <img src="../../../../public//confirmAnOrder/LOGO.png" alt="" />
          </div>
          <div class="searchBox">
            <div class="commodity">
              <p class="on">商品</p>
              /
              <p>店铺</p>
            </div>
            <input type="text" placeholder="请输入关键词搜索" />
            <button>搜索</button>
          </div>
          <div class="shopCarBox">
            <img
              src="../../../../public//confirmAnOrder/gouwuchexuanzhong.png"
              alt=""
            />购物车
            <p>39</p>
          </div>
        </div>
        <div class="topBox-bottom">
          <div>当前位置:</div>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>购物车</el-breadcrumb-item>
            <el-breadcrumb-item>提交订单</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
      </div>
      <div class="bottomBox">
        <div class="selectBox">
          <div class="select-blueLeft"></div>
          <p class="selectBox-way">选择收货地址</p>
          <p class="addresses" @click="mangeAddress">管理收货地址</p>
        </div>
        <div class="selectAddress">
          <div
            :class="['item', selectIndex === index ? 'active' : '']"
            v-for="(item, index) in changeListAddress"
            :key="index"
            @click="addressChange(index)"
          >
            <img src="../../../../public/submitOrder/组 332.png" alt="" />
            <span class="label">寄送至</span>
            <i class="el-icon-success" v-if="selectIndex === index"></i>
            <div class="circle" v-else></div>
            <div class="address-main">
              <span>{{ item.province }} </span>
              <span style="margin: 0 12px">{{ item.city }}</span>
              <span>{{ item.detailsAddress }}</span>
              <span>{{ item.receiver }}</span>
              <span>{{ item.mobile }}</span>
            </div>
            <span class="default" v-if="item.isDefault">默认地址</span>
            <span class="edit" v-if="selectIndex === index">修改本地址</span>
          </div>
          <span
            class="otherAddresses"
            @click="otherAddresses"
            style="
              cursor: pointer;
              color: #626262;
              font-size: 16px;
              padding-left: 175px;
            "
          >
            {{ textAddressChange }}
          </span>
        </div>
        <div class="selectBox">
          <div class="select-blueLeft"></div>
          <p class="selectBox-order">订单信息确认</p>
        </div>
        <div class="productTable">
          <el-table
            style="width: 100%; margin-left: -50px"
            :header-cell-style="headerCellStyle"
            class="header-table"
          >
            <el-table-column label="商品信息" width="335">
              <!-- <img :src="item.goodsPhoto" alt="" /> -->
            </el-table-column>
            <el-table-column label="单价" width="335"> </el-table-column>
            <el-table-column label="数量" width="375"></el-table-column>
            <el-table-column prop="city" label="小计" width="295">
            </el-table-column>
          </el-table>
          <div v-for="(item, index) in getOrderList" :key="index">
            <div class="shop">
              店铺：
              <p>{{ item.mallName }}</p>
            </div>
            <el-table
              :data="item.shopcarGoods"
              style="width: 100%; margin-left: -50px"
              :header-cell-style="headerCellStyle"
              :show-header="false"
            >
              <el-table-column width="100">
                <template slot-scope="{ row }">
                  <img
                    :src="row.goodsPhoto"
                    alt=""
                    style="width: 80px; height: 80px"
                  />
                </template>
              </el-table-column>
              <el-table-column width="315">
                <template slot-scope="{ row }">
                  <p>{{ row.goodsName }}</p>
                  <p style="color: #ccc; font-size: 12px">{{ row.attrDesc }}</p>
                </template>
              </el-table-column>
              <el-table-column prop="priceCurrent" label="单价" width="320">
              </el-table-column>
              <el-table-column label="数量" width="405">
                <template slot-scope="scope">
                  <div>
                    <el-input-number
                      v-model="scope.row.goodsQuantity"
                      @change="handleChange"
                      :min="1"
                      :max="9999"
                      label="描述文字"
                      size="mini"
                    >
                    </el-input-number>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="小计" width="175">
                <template slot-scope="{ row }">
                  <p>￥{{ row.goodsQuantity * row.priceCurrent }}</p>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="productRable_bottom">
            <div class="ordernotes">
              <b>订单备注:</b>
              <el-input
                type="text"
                placeholder="选填,请和商家协商一致,付款后商家可见"
                v-model="text"
                maxlength="200"
                show-word-limit
              >
              </el-input>
            </div>
            <div class="shoppreferential">
              <!-- <div class="shoppreferential_top">
                <span>店铺优惠:</span>
                <input type="text" />
                <span>-200</span>
              </div> -->
              <div class="shoppreferential_middle">
                <span>送货方式:</span>
                <span>普通配送 快递 免邮</span>
                <span>0.00</span>
              </div>
              <div class="shoppreferential_bottom">
                <template>
                  <span>店铺合计(含运费)</span>
                  <span>￥{{ paidAmount }}</span>
                </template>
              </div>
            </div>
          </div>

          <div class="information">
            <div class="disbursements">
              <p>实付款</p>
              <p>￥</p>
              <b>{{ paidAmount }}</b>
            </div>
            <div>
              <div class="sendd">
                <p>寄送至 :</p>
                <p>
                  <!-- {{ item.province }}
                  {{ item.city }}
                  {{ item.detailsAddress }} -->
                  河北省 邯郸市 丛台区 某某街道某某某小区6号楼2单元205
                  <!-- {{ mailingAddress }} -->
                </p>
              </div>
              <div class="consignee">
                <p>收货人 :</p>
                <p>
                  某某某(收)
                  <!-- {{ item.receiver }} -->
                </p>
                <p>
                  15555555487
                  <!-- {{ item.mobile }} -->
                </p>
              </div>
            </div>
          </div>
        </div>
        <div class="submitButton">
          <div class="goback">
            <img src="../../../../public//submitOrder/返回.png" alt="" />
            <p class="shopcar">返回购物车</p>
          </div>
          <button class="submit_btn" @click="doSubmit">提交订单</button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
// eslint-disable-next-line import/no-cycle
import {
  getOrder,
  getAddress,
  getInsert,
} from "@/framework/api/getOrderSure/getOrderSure";

export default {
  name: "submitOrder",
  data() {
    return {
      comeForm: 1,
      paidAmount: 0,
      totalPrice: 0,
      selectIndex: 0,
      textAddress: "显示全部地址",
      changeText: "使用其他地址",
      showAllAddress: true,
      radio: "0",
      text: "",
      mailingAddress: "",
      getOrderList: [],
      getAddressList: [],
      orderDTO: {
        comeFrom: "",
        totalPrices: "",
        consigneeName: "string",
        consigneePhone: "string ",
        consigneeAddress: "string",
        detailAddress: "string",
        proviceCode: "string",
        cityCode: "string",
        countyCode: "string",
        orderDetailesDTOList: [{}],
      },
    };
  },
  computed: {
    textAddressChange() {
      if (this.textAddress) {
        return this.textAddress;
      } else {
        return this.changeText;
      }
    },
    changeListAddress() {
      if (this.showAllAddress) {
        return this.getAddressList.slice(0, 5);
      } else {
        return this.getAddressList;
      }
    },
  },
  mounted() {
    this.getList();
    this.getAddress();
  },

  methods: {
    addressChange(index) {
      this.selectIndex = index;
      this.isDefault = index;
    },
    doSubmit() {
      var index = this.selectIndex;
      this.orderDTO.paidAmount = this.paidAmount * 100;
      this.orderDTO.comeFrom = this.comeForm;
      this.orderDTO.consigneeName = this.getAddressList[index].receiver;
      this.orderDTO.consigneePhone = this.getAddressList[index].mobile;
      this.orderDTO.consigneeAddress =
        this.getAddressList[index].detailsAddress;
      this.orderDTO.proviceCode = this.getAddressList[index].provinceCode;
      this.orderDTO.cityCode = this.getAddressList[index].cityCode;
      this.orderDTO.countyCode = this.getAddressList[index].districtCode;
      this.orderDTO.proviceName = this.getAddressList[index].province;
      this.orderDTO.cityName = this.getAddressList[index].city;
      this.orderDTO.countyName = this.getAddressList[index].district;
      this.orderDTO.totalPrices = this.totalPrice * 100;
      this.orderDTO.orderDetailesDTOList = [];
      this.getOrderList.forEach((item) => {
        var mallCode = item.mallCode;
        for (var i = 0; i < item.shopcarGoods.length; i++) {
          var goods = item.shopcarGoods[i];
          var orderDetails = {};
          orderDetails.mallCode = mallCode;
          orderDetails.goodsId = goods.goodsId;
          orderDetails.goodsName = goods.goodsName;
          orderDetails.goodsThumbnail = goods.goodsPhoto;
          orderDetails.specAttr = goods.attrDesc;
          orderDetails.specAttrId = goods.attrId;
          orderDetails.price = goods.priceCurrent * 100;
          orderDetails.amount = goods.goodsQuantity;
          this.orderDTO.orderDetailesDTOList.push(orderDetails);
        }
      });
      console.log("order", this.orderDTO);
      getInsert(this.orderDTO)
        .then((res) => {
          console.log(res.data);
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 获取店铺商品数据
    getList() {
      getOrder().then((response) => {
        this.getOrderList = response.data.list;
        this.paidAmount = response.data.totalAmount;
        this.comeForm = response.data.comeForm;
        this.handleChange();
      });
    },
    // 获取地址数据
    getAddress() {
      getAddress().then((response) => {
        this.getAddressList = response.data.records;
        // this.mailingAddress = response.data.records;
      });
    },
    handleChange() {
      var totalPrice = 0;
      this.getOrderList.forEach((item) => {
        for (var i = 0; i < item.shopcarGoods.length; i++) {
          var goods = item.shopcarGoods[i];
          var subtotal = goods.goodsQuantity * goods.priceCurrent;
          goods.subtotal = subtotal;
          totalPrice = totalPrice + subtotal;
        }
        this.paidAmount = totalPrice;
        this.totalPrice = totalPrice;
      });
    },
    mangeAddress() {},
    headerCellStyle({ column }) {
      if (column.label === "商品信息") {
        return { background: "#f8f8f8" };
      } else if (column.label === "单价") {
        return { background: "#f8f8f8" };
      } else if (column.label === "数量") {
        return { background: "#f8f8f8" };
      } else if (column.label === "小计") {
        return { background: "#f8f8f8" };
      }
    },
    otherAddresses() {
      this.textAddress = this.changeText;
      this.showAllAddress = false;
    },
  },
};
</script>

<style lang="scss" scoped>
* {
  list-style: none;
  box-sizing: border-box;
  padding: 0;
  // margin: 0 auto;
}

.main {
  width: 1340px;
  height: auto;

  .topBox {
    width: 1340px;
    height: 200px;
    display: flex;
    flex-direction: column;

    .topBox-top {
      width: 1340px;
      height: 144px;
      border-bottom: solid 1px #1289ff;
      display: flex;
      justify-content: space-around;
      align-items: center;

      .logo {
        // margin-top: 45px;
        img {
          width: 233px;
          height: 55px;
        }
      }

      .searchBox {
        width: 643px;
        height: 45px;
        display: flex;
        justify-content: center;
        align-items: center;
        border-radius: 4px;
        position: relative;

        .commodity {
          position: absolute;
          top: -25px;
          right: 542px;
          display: flex;
          justify-content: space-between;
          // margin-left: 50px;
          font-size: 14px;

          p {
            display: inline-block;
            width: 28px;
            height: 20px;
            cursor: pointer;
            margin: 0 5px;
          }

          .on {
            color: #1289ff;
          }
        }

        input {
          width: 532px;
          height: 45px;
          padding-left: 17px;
          line-height: 45px;
          outline: none;
          border: 1.5px solid #1289ff;
          border-radius: 4px;
        }

        button {
          font-size: 16px;
          width: 111px;
          height: 45px;
          background: #1289ff;
          color: #fff;
          border: none;
          border-radius: 4px;
          cursor: pointer;
          margin-left: -5px;
        }
      }

      .shopCarBox {
        width: 140px;
        height: 45px;
        border: 1px solid #d3d3d3;
        border-radius: 4px;
        display: flex;
        justify-content: center;
        align-items: center;
      }
    }

    .topBox-bottom {
      width: 1340px;
      height: 56px;
      line-height: 56px;
      // display: flex;
      // justify-content: space-around;
    }
  }

  .bottomBox {
    width: 1240px;
    height: auto;

    // background: #ccc;
    .selectBox {
      margin-top: 35px;
      width: 1240px;
      height: 19px;
      margin-top: 25px;
      margin-bottom: 13px;
      display: flex;
      justify-content: space-around;

      .select-blueLeft {
        width: 4px;
        height: 19px;
        border-radius: 2px;
        background: #1289ff;
        margin-left: -50px;
      }

      .selectBox-way {
        margin-left: -340px;
        font-weight: 500;
        font-size: 19px;
        line-height: 19px;
        color: #2b2b2b;
      }

      .selectBox-order {
        margin-left: -1150px;
        font-weight: 500;
        font-size: 19px;
        line-height: 19px;
        color: #2b2b2b;
      }

      .addresses {
        color: #1289ff;
        margin-left: 760px;
        margin-right: -45px;
        cursor: pointer;
      }
    }

    .selectAddress {
      width: 1340px;
      height: auto;
      margin-top: 20px;
      margin-left: -50px;
      // display: flex;
      // justify-content: space-around;

      > .item {
        display: flex;
        align-items: center;
        padding: 12px 0;
        > .label {
          flex: none;
          margin: 0 24px 0 12px;
          color: #1289ff;
          opacity: 0;
        }
        > img {
          margin: 0 6px;
          opacity: 0;
        }

        > .default {
          color: #626262;
          font-size: 14px;
          margin-left: 24px;
        }

        ::v-deep .el-checkbox {
          margin-left: 24px;
          .el-checkbox__input.is-checked .el-checkbox__inner {
            background-color: #1289ff;
            border-color: #1289ff;
          }
        }

        .el-icon-success {
          color: #1289ff;
          font-size: 20px;
          margin: 0 12px;
        }
        .circle {
          width: 20px;
          height: 20px;
          background: #fff;
          border: 1px solid #d6d6d6;
          border-radius: 999em;
          margin: 0 12px;
        }

        .address-main {
          margin: 0 24px 0 12px;
          cursor: pointer;
          span{
            padding: 0 3px;
          }
          :nth-child(4) {
            padding-left: 40px;
          }
        }
      }
      > .item.active {
        border: 1px solid #3f87f7;
        background: #f0f8fd;
        margin-bottom: 12px;
        cursor: pointer;

        > .label {
          opacity: 1;
        }
        > img {
          opacity: 1;
        }
        > .default {
          font-size: 18px;
        }
        > .edit {
          color: #1289ff;
          font-size: 16px;
          cursor: pointer;
        }
        .address-main {
          font-weight: 700;
          color: #3c3c3c;
          font-size: 20px;
        }
      }

      .el-radio {
        // width: 1340px;
        // height: 54px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        border-radius: 2px;
      }

      .selectAddress-address {
        width: 1340px;
        height: 54px;
        border-radius: 2px;
        margin-left: -50px;
        display: flex;
        align-items: center;
        .on {
          font-size: 20px;
          font-weight: 500;
          margin-left: -100px;
        }

        .el-radio {
          display: flex;
          justify-content: space-between;
        }

        p {
          font-weight: 500;
          font-size: 16px;
          line-height: 28px;
          text-align: left;
          color: #3c3c3c;
          padding-right: 10px;
        }
      }
    }

    .productTable {
      width: 1340px;
      height: 711px;
      margin-left: -4px;
      .header-table {
        ::v-deep .el-table__body-wrapper {
          display: none;
        }
      }

      ::v-deep .el-table th > .cell {
        color: #2b2b2b;
        margin-left: 88px;
      }
      ::v-deep .el-table_2_column_6 {
        margin-left: 50px;
      }
      .shop {
        margin: 12px -38px;
        display: flex;
        justify-content: space-around;
        p {
          margin-left: -5px;
        }
      }
      ::v-deep .el-table__row > .el-table_2_column_6 el-table__cell {
        margin-left: 80px;
      }
      ::v-deep .el-table__row > .cell {
        color: #ff6b00;
        font-size: 20px;
        font-weight: 700;
      }

      .productRable_bottom {
        width: 1340px;
        margin-left: -55px;
        height: 245px;
        background: #f7faff;
        border-bottom: solid 1px #1289ff;
        display: flex;
        justify-content: space-around;

        .ordernotes {
          width: 526px;
          height: 86px;
          display: flex;
          justify-content: space-between;
          margin-left: 17px;
          margin-top: 22px;

          p {
            font-size: 12px;
            font-weight: 400;
          }
        }

        .shoppreferential {
          width: 627px;
          height: 189px;
          margin-top: 22px;
          margin-left: 70px;
          display: flex;
          flex-direction: column;

          .shoppreferential_top {
            width: 627px;
            height: 44px;
            margin-right: 21px;
            display: flex;
            justify-content: space-around;
            line-height: 44px;

            :nth-child(1) {
              font-size: 16px;
              padding-right: 18px;
            }

            :nth-child(2) {
              width: 255px;
              height: 44px;
              border-radius: 2px;
              background: #fff;
              outline: none;
              border: 1px solid #c3c3c3;
              margin-right: 110px;
            }

            :nth-child(3) {
              font-weight: 700;
              font-size: 20px;
              color: #ff6b00;
            }
          }

          .shoppreferential_middle {
            width: 626px;
            height: 29px;
            line-height: 29px;
            margin-top: 26px;
            margin-right: 21px;
            display: flex;
            justify-content: space-around;

            :nth-child(1) {
              padding-right: 36px;
              font-weight: 400;
              font-size: 16px;
            }

            :nth-child(2) {
              padding-right: 180px;
              font-weight: 400;
              font-size: 16px;
            }

            :nth-child(3) {
              font-weight: 700;
              font-size: 20px;
              color: #ff6b00;
            }
          }

          .shoppreferential_bottom {
            width: 299px;
            height: 29px;
            line-height: 29px;
            margin-right: 15px;
            margin-top: 56px;
            display: flex;
            justify-content: space-around;

            :nth-child(1) {
              padding-right: 25px;
              font-weight: 400;
              font-size: 20px;
            }

            :nth-child(2) {
              font-weight: 700;
              font-size: 20px;
              color: #ff6b00;
            }
          }
        }
      }
    }

    .information {
      margin-top: 20px;
      margin-right: 55px;
      width: 596px;
      height: 191px;
      border-radius: 2px;
      background: #fff;
      border: 2px solid #1289ff;
      display: flex;
      flex-direction: column;

      .disbursements {
        width: 210px;
        height: 45px;
        margin-top: 24px;
        margin-right: 19px;
        display: flex;
        justify-content: space-around;
        line-height: 45px;

        :nth-child(1) {
          font-size: 20px;
          font-weight: 700;
          padding-top: 3px;
          padding-left: 20px;
        }

        :nth-child(2) {
          font-size: 14px;
          font-weight: 700;
          color: #ff6b00;
          padding-top: 3px;
          padding-left: 55px;
        }

        :nth-child(3) {
          font-size: 25px;
          font-weight: 700;
          color: #ff6b00;
        }
      }

      .sendd {
        width: 549px;
        height: 27px;
        margin-top: 26px;
        margin-right: 19px;
        display: flex;
        justify-content: space-around;

        :nth-child(1) {
          font-weight: 700;
          font-size: 18px;
        }
      }

      .consignee {
        width: 304px;
        height: 27px;
        margin-top: 23px;
        margin-right: 19px;
        display: flex;
        justify-content: space-around;

        :nth-child(1) {
          font-weight: 700;
          font-size: 18px;
        }
      }
    }

    .submitButton {
      margin-right: -44px;
      margin-top: 99px;
      width: 596px;
      height: 40px;
      display: flex;
      justify-content: space-between;

      .goback {
        width: 84px;
        height: 24px;
        margin-left: 0px;
        // margin-top: 15px;
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;

        img {
          width: 15px;
          height: 15px;
        }

        .shopcar {
          font-size: 12px;
          color: #1289ff;
        }
      }

      .submit_btn {
        width: 146px;
        height: 40px;
        cursor: pointer;
        margin-right: 0px;
        border-radius: 4px;
        background: #1289ff;
        border: none;
        color: #fff;
      }
    }
  }
}
</style>